$(function () {
    var blog_table;
    layui.use('table', function () {
        var table = layui.table;
        blog_table = table.render({
            elem: '#blog_table'
            , height: 625 //容器高度
            , cols: [[
                {fixed: 'left', type: 'checkbox'},
                {field: 'id', hide: true},
                {field: 'title',title:'标题'},
                {field: 'image',templet:'#image',title:'封面图片'},
                {field: 'views',title:'浏览量'},
                {field: 'status',templet:'#status',title:'状态'},
                {field: 'catagory',templet:'#catagory',title:'博客分类'},
                {field: 'createTime',title:'添加时间'},
            ]] //设置表头
            , toolbar: true
            , page: true
            , url: '/table/list/blog'
        });
    })


    $("#blog_delete_btn").click(function () {
        layui.use('table',function () {
            var table = layui.table;
            var checkStatus = table.checkStatus('blog_table');
            var data = checkStatus.data;
            if(data.length>0){
                layer.confirm('真的删除麽',function () {
                    $.ajax({
                        type:"post",
                        url:'/blog/delete',
                        dataType:"json",
                        contentType: "application/json;charset=utf-8",
                        data:JSON.stringify(data),
                        success:function (r) {
                            if(r.status='success'){
                                layer.msg("删除成功");
                            }else{
                                layer.msg("error");
                            }
                            blog_table = table_reload_del(blog_table,"blog_table");
                        }
                    })

                })
            }else{
                layer.msg("请选中至少一条数据");
            }
        })
    })



    $("#blog_select_btn").click(function () {
        var reg = new RegExp("%","g")
        var key = $("#key").val().replace(reg,"");
        layui.use('table', function () {
            var table = layui.table;
            blog_table = table.render({
                elem: '#blog_table'
                , height: 625 //容器高度
                , cols: [[
                    {fixed: 'left', type: 'checkbox'},
                    {field: 'id', hide: true},
                    {field: 'title',title:'标题'},
                    {field: 'views',title:'浏览量'},
                    {field: 'status',templet:'#status',title:'状态'},
                    {field: 'catagory',templet:'#catagory',title:'博客分类'},
                    {field: 'createTime',title:'添加时间'},
                ]] //设置表头
                , toolbar: true
                , page: true
                , url: '/table/list/blog/'+key
            });
        })
    })


    $("#blog_update_btn").click(function () {
        layui.use('table',function () {
            var table = layui.table;
            var checkStatus = table.checkStatus('blog_table');
            var data = checkStatus.data;
            if(data.length==1){
                console.log(data);
                window.location.href="/blog/update/"+data[0].id;
            }else{
                layer.msg("请选中一条数据");
            }
        })
    })



})















